package com.action;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Map;

import com.model.product;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.util.DB;

public class detaileditem extends ActionSupport


{

	
	private String checklogin;
	
	public String getChecklogin() {
		return checklogin;
	}

	public void setChecklogin(String checklogin) {
		this.checklogin = checklogin;
	}


	private Integer prodid;
	
	public Integer getProdid() {
		return prodid;
	}

	public void setProdid(Integer prodid) {
		this.prodid = prodid;
	}

	
   ArrayList<product> prodarr=new ArrayList<product>();
	
	public ArrayList<product> getProdarr() {
		return prodarr;
	}

	public void setProdarr(ArrayList<product> prodarr) {
		this.prodarr = prodarr;
	}

	
	
	
	ResultSet res,res4;
	
	public String execute()throws Exception
	{
		Map session;
		session=ActionContext.getContext().getSession();
		
		System.out.println("The prodid is"+prodid);
		
		 
		 String query="select * from product where prodid="+prodid+";";
		 res=DB.readFromBmtcDB(query);
		 while(res.next())
	
			 
		 {
			 
			 Float price;
			 
			 product p=new product();
			 
			 Float start_price=res.getFloat("start_price");
			 Float buy_itnow_price=res.getFloat("buy_itnow_price");
			 
			 if(start_price==0.0)
				 price=buy_itnow_price;
			 else
				 price=start_price;
			 
			 Integer prodid=res.getInt("prodid");
			 session.put("prodid",prodid);
			 
			 
			 p.setProdid(res.getInt("prodid"));
			 p.setTitle(res.getString("title"));
			 p.setQuantity(res.getInt("quantity"));
			 p.setDescription(res.getString("description"));
			 p.setCond(res.getString("cond"));
			 p.setPayment_method(res.getString("payment_method"));
			 p.setBuy_itnow_price(price);
			 p.setSubcatid(res.getInt("subcatid"));
			 p.setId(res.getInt("id"));
			 //p.setShipping_service(res.getString("shipping_service"));
	
			 
			 String query4="select * from shipping where prodid="+prodid+";";
			 res4=DB.readFromBmtcDB(query4);
			 while(res4.next())
		
				 
			 {
				 
				 Float shipping_cost=res4.getFloat("shipping_cost");
				 
				 //p.setShipping_cost(res4.getFloat("shipping_cost"));
				 p.setShipping_service(res4.getString("shipping_service"));
				 p.setHandling_time(res4.getString("handling_time"));
				 p.setFree_shipping(res4.getString("free_shipping"));
				 p.setShipping_cost(shipping_cost);
				  
				 
			 }
			 
			 
			 
			 prodarr.add(p);
			 
		
			if(start_price==0.0) 
		return "detailed";
			else
				return "detailed1";
		 }
		
		 return "success";
		
	}
	
	
}
